package org.csu.mypetstore.controller;

import jakarta.servlet.http.HttpSession;
import org.csu.mypetstore.aspect.LogAnnotation;
import org.csu.mypetstore.commonResponse.CommonResponse;
import org.csu.mypetstore.domin.Account;
import org.csu.mypetstore.domin.LogTable;
import org.csu.mypetstore.service.LogTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static org.csu.mypetstore.controller.AccountController.isLogin;

@RestController
@RequestMapping("/logTable")
public class LogTableController {
    @Autowired
    LogTableService logTableService;
    //用户查看日志
    @LogAnnotation(module="logTable",operation = "用户查看日志")
    @GetMapping("")
    CommonResponse<List<LogTable>> getLogTableListByUsername(HttpSession session){
        CommonResponse<Account> commonResponse=isLogin(session);
        if (commonResponse.getStatus() == 0) {
            return CommonResponse.createForError("未登录");
        }
        return logTableService.getLogTableListByUsername(commonResponse.getData().getUserid());
    }
}
